//
//  AppDelegate.m
//  TWSWeibo
//
//  Created by Twisal on 2016/12/27.
//  Copyright © 2016年 Twisal. All rights reserved.
//

#import "AppDelegate.h"
#import <UIKit/UIKit.h>
#import "TWSTabBarController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _window = [[UIWindow alloc] init];
    _window.backgroundColor = [UIColor whiteColor];
    _window.rootViewController = [[TWSTabBarController alloc] init];
    [_window makeKeyAndVisible];
    [self loadJson];
    return YES;
}



/**
 模拟网络请求json数据
 */
- (void)loadJson {
   
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        // 1. 获取当前的json数据
        NSURL *url = [[NSBundle mainBundle] URLForResource:@"main.json" withExtension:nil];
        NSData *data = [NSData dataWithContentsOfURL:url];
        
        // 2. 获取要写入的沙盒路径
        NSString *docDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
        NSString *jsonPath = [docDir stringByAppendingPathComponent:@"main.json"];
        
        // 3. 写入沙盒
        [data writeToFile:jsonPath atomically:YES];
        NSLog(@"保存的json沙盒路径为: %@", jsonPath);
    });
}

@end
